<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
<title>{{$pageTitle}}-{{$site[title]}}</title>
<META NAME="ROBOTS" CONTENT="INDEX,FOLLOW">
<meta name="Keywords" content="{{if $seokeywords}}{{$seokeywords}}{{else}}{{$site[seokeywords]}}{{/if}}" />
<meta name="Description" content="{{if $seodescription}}{{$seodescription}}{{else}}{{$site[seodescription]}}{{/if}}" />
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
	{{$this->Html->script(array('html5.js'))}}
<![endif]-->
{{$this->Html->meta('icon')}}

{{$this->Combinator->less();}}

{{$this->Html->css(array('ui-customer',))}}
{{$this->Html->script(array(
            'jquery/jquery.min.js',
            'bootstrap.min.js',
        ));
}}

<script type="text/javascript">
var BASEURL = "{{APP_SUB_DIR}}";
var ADMIN_BASEURL = BASEURL+"/manage";
</script>
</head>
<body>
<style>
.answers{
	color: #666666;
    margin: 0 40px;
}
.affix{top:0px;}
</style>

<div class="container clearfix">
<div class="row">
	<div class="ui-contain col-md-3">
		<div class="ui-portlet  panel panel-default" style="margin:0 0;" data-spy="affix" data-offset-top="150">
			<div class="clearfix panel-heading ui-portlet-header" >
			     <span class="title" style="margin:0 0px;"><h3>Welcome <?php echo $qqnick; ?></h3></span>
			     <span class="title"><h3>问题分类</h3></span>            
			</div>
			<div class="ui-corner-bottom ui-portlet-content">
				<ul class="nav nav-list" >
				<li {{if $cateid==385875968}} class="active"{{/if}}><a class=" ui-menu-first" href="<?php echo $basedir;?>/auto_wenwens/index?cateid=385875968">教育科学</a></li><li class="divider"></li>
				<li {{if $cateid==387121152}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=387121152">&nbsp;&nbsp;学习帮助</a></li><li class="divider"></li>
				<li {{if $cateid==391577600}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=391577600">&nbsp;&nbsp;理工学科</a></li><li class="divider"></li>
				<li {{if $cateid==1193607168}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=1193607168">&nbsp;&nbsp;孩子教育</a></li><li class="divider"></li>
				
				
				
				<li {{if $cateid==318767104}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=318767104">电脑数码</a></li><li class="divider"></li>
				<li {{if $cateid==1090519040}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=1090519040">QQ专区</a></li><li class="divider"></li>
				<li {{if $cateid==83886080}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=83886080">生活家居</a></li><li class="divider"></li>
				<li {{if $cateid==553648128}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=553648128">健康医疗</a></li><li class="divider"></li>
				<li {{if $cateid==855638016}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=855638016">艺术文学</a></li><li class="divider"></li>
				<li {{if $cateid==687865856}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=687865856">社会人文</a></li><li class="divider"></li>
				<li {{if $cateid==1191182336}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=1191182336">情感家庭</a></li><li class="divider"></li>
				<li {{if $cateid==150994944}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=150994944">娱乐明星</a></li><li class="divider"></li>
				<li {{if $cateid==620756992}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=620756992">投资理财</a></li><li class="divider"></li>
				
				<li {{if $cateid==1627389952}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=1627389952">休闲爱好</a></li><li class="divider"></li>
				<li {{if $cateid==16777216}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=16777216">游戏</a></li><li class="divider"></li>
				<li {{if $cateid==922746880}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=922746880">奥运体育</a></li><li class="divider"></li>
				<li {{if $cateid==1879113728}} class="active"{{/if}}><a href="<?php echo $basedir;?>/auto_wenwens/index?cateid=1879113728">北京地区问题</a></li><li class="divider"></li>
		
				</ul>
			</div>
		</div>
	</div>
	
	<div class="ui-contain panel panel-default col-md-9">
		<div class="ui-portlet ">
			<div class="clearfix panel-heading ui-portlet-header" >
			   <span class="title"><h3>问问问题列表</h3></span>            
			</div>
			<div class="ui-corner-bottom ui-portlet-content">
				<ul id="wenwen-question-list" class="clearfix portlet-content-list">
				    <?PHP foreach($questions as $url => $ques) {	?>	
					<li class="regionlist clearfix" id="question-<?php echo $ques['qid'];?>">
						<a href="http://wenwen.soso.com<?php echo $url; ?>" target="_blank"  style="float:right;">查看原题</a>
						<a data-qid="<?php echo $ques['qid'];?>" class="answer-title" href="javascript:void(0)"><h3><?php echo $ques['title'];?>{{if $ques['num']}} ------(已有回答<font color="red">{{$ques['num']}}</font>){{/if}}</h3></a>
					</li>
					<?php } ?>
					<div class="clear"></div>
				</ul>
				<?php echo $page_navi; ?>
			</div>
		</div>
	</div>
</div>
</div>
<script>
$(function(){
	
	$(document).on('click','.answer-title',function(){
		var obj = $(this);
		var qid = $(this).data('qid');
		if(obj.closest('li').find('.answers').size()>0){
			obj.closest('li').find('.answers').toggle();
			return false;
		}
		obj.closest('li').append('<div class="loading"><?php echo $this->Html->image("ajax/circle_ball.gif");?></div>');
		$.ajax({
			type: "POST",
			url: BASEURL + '/auto_wenwens/getans.json',
			data:{'word':$(this).html()},
			dataType:'json',
			success:function(data){			
				var html = '<ul class="answers">';
				for(var i in data){
					if(data[i]==null) break;
					html += '<li>'
					+'<a class="btn btn-primary answer-question" data-qid="'+qid+'" data-bqid="'+data[i].bqid+'" style="float:right;" title="用这个答案来回答问题">回答</a>'
					+'<h4><a href="'+data[i].url+'" target="_blank">'+data[i].title+(data[i].digg>0?'(<i class="icon-thumbs-up">'+data[i].digg+')':'')+'</i></a></h4><div class="content">'+data[i].content+'</div></li>';
				}
				html +='</ul>';
				obj.closest('li').find('.loading').remove();
				obj.closest('li').append(html);
			}
		});
	});
	$(document).on('click','.change-verify-code',function(){
		$(this).siblings('img').attr('src',BASEURL + '/auto_wenwens/getWenwenVerifyCode?rdm='+Math.random());
	})
	$(document).on('click','.answer-question',function(){
		var obj = $(this);
		var qid = $(this).data('qid');
		var bqid = $(this).data('bqid');
		if(obj.closest('li').find('form').size()>0){
			return false;
		}
		
		$.ajax({
			type: "GET",
			url: BASEURL + '/auto_wenwens/getAnswerContent',
			data:{'bqid':bqid,'qid':qid},
			dataType:'json',
			success:function(data){	
				var content = data.content;//complete dataType html xhr.responseText
				if(content=="no"){
					content = obj.closest('li').find('div.content').html();
				}
				var verifyhtml ="";
				if(data.need_verify_code){
					verifyhtml+='<input type="text" autocomplete="off" maxlength="4" value="" name="verifycode"> &nbsp;&nbsp; <img  width="130" height="53" src="'+BASEURL + '/auto_wenwens/getWenwenVerifyCode"'+'>&nbsp;'
					+'<a tabindex="-1" class="change-verify-code" href="javascript:void(0)">看不清，换一个</a>';
				}
				//obj.closest('li').find('div.content').hide();
				obj.closest('li').append('<form action="#" method="POST">'
						+ '<input name="qid" type="hidden" value="'+qid+'"/>'
						+ '<input name="bqid" type="hidden" value="'+bqid+'"/>'
						+ '<textarea name="answer_content" style="width:95%;height:90px;">'+content+"\n"+'</textarea><br/>'
						+ '<input name="teamcooperate" checked="checked" type="checkbox" id="teamCooperate_'+qid+'"><label for="teamCooperate_'+qid+'" style="display: inline;">以团队名义回答</label>'
						+ verifyhtml
						+ '<input type="submit" class="btn btn-primary" onclick="return submit_question_form(this.form)" value="提交" />'
						+ '</form>'
				);//希望对你有帮助。
			}
		});
		return false;
	});	
});

function submit_question_form(form){
	$(form).append('<span id="start-submit-ans"><?php echo $this->Html->image("ajax/circle_ball.gif");?></span>');
	
	$.ajax({
		type: "POST",
		url: BASEURL + '/auto_wenwens/answer',
		data:$(form).serialize(),
		dataType:'html',
		success:function(data){
			$('#start-submit-ans').remove();
			$(form).append(data);
		}
	});
	return false;
}
</script>

{{$this->Html->script(array('jquery/jquery.infinitescroll.js'))}}
<script>
$(function(){
	var pageobj = $('div.pagelink');
	//pageobj.hide();
	  var is_loading = false;
	  $('#wenwen-question-list').infiniteScroll({
		    threshold: 400,
		    onEnd: function() {
		    	alert('No more results!');
		    },
		    onBottom: function(callback) {
		        var nextobj = $('div.pagelink').find('.ui-page-active').next('a');
		        
				if(nextobj.size()==0){
					callback(false);
					return;
				}
		        if(!is_loading){
		        	is_loading = true;
		        	$('div.pagelink').before('<div id="loading-next-page"><?php echo $this->Html->image("ajax/circle_ball.gif");?></div>');
		        	$.ajax({
		    			type: "GET",
		    			url: nextobj.attr('href'),
		    			dataType:'html',
		    			success:function(data){
		    				$(data).find('#wenwen-question-list li').each(function(i){
		    					var id = $(this).attr('id');
		    					if($('#'+id).size()==0){
		    						// 不重复的问题，加入到页面
		    						$(this).appendTo($('#wenwen-question-list'));
		    					}
		    				});
		    				pageobj.html($(data).find('div.pagelink').html());
		    				callback(true);
		    				is_loading = false;
		    				$('#loading-next-page').remove();
		    			}
		    		});
		        }
		    }
		});

	  /*
	  $container.infinitescroll({
	        bufferPx     : 200, //离分页底部还有bufferPx像素时就开始加载下一页的内容 ，设置大一些体验效果会好一些
		    loading : {img:"{{$this->Html->url('/img/ajax/loading.gif')}}",msgText:"正在加载新的问题...",finishedMsg:"亲，没有更多的啦。。。"},
		    animate: true,extraScrollPx:-200,
		    debug        : true,
		    navSelector  : "div.pagelink", // selector for the paged navigation (it will be hidden)
		    nextSelector : "div.pagelink a:first",  // selector for the NEXT link (to page 2)
		    itemSelector : "#wenwen-question-list"  // selector for all items you'll retrieve
	  	},
	    function(newElements) {
	  		alert(123);
	        var $newElems = $(newElements);
	       
	    });*/
});

</script>